/*
 * Copyright (c) 2022 Huawei Device Co., Ltd.
 * Licensed under the Apache License, Version 2.0 (the "License");
 * you may not use this file except in compliance with the License.
 * You may obtain a copy of the License at
 *
 *     http://www.apache.org/licenses/LICENSE-2.0
 *
 * Unless required by applicable law or agreed to in writing, software
 * distributed under the License is distributed on an "AS IS" BASIS,
 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
 * See the License for the specific language governing permissions and
 * limitations under the License.
 */

"use strict";

function _typeof(o) { "@babel/helpers - typeof"; return _typeof = "function" == typeof Symbol && "symbol" == typeof Symbol.iterator ? function (o) { return typeof o; } : function (o) { return o && "function" == typeof Symbol && o.constructor === Symbol && o !== Symbol.prototype ? "symbol" : typeof o; }, _typeof(o); }
function ownKeys(e, r) { var t = Object.keys(e); if (Object.getOwnPropertySymbols) { var o = Object.getOwnPropertySymbols(e); r && (o = o.filter(function (r) { return Object.getOwnPropertyDescriptor(e, r).enumerable; })), t.push.apply(t, o); } return t; }
function _objectSpread(e) { for (var r = 1; r < arguments.length; r++) { var t = null != arguments[r] ? arguments[r] : {}; r % 2 ? ownKeys(Object(t), !0).forEach(function (r) { _defineProperty(e, r, t[r]); }) : Object.getOwnPropertyDescriptors ? Object.defineProperties(e, Object.getOwnPropertyDescriptors(t)) : ownKeys(Object(t)).forEach(function (r) { Object.defineProperty(e, r, Object.getOwnPropertyDescriptor(t, r)); }); } return e; }
function _defineProperty(obj, key, value) { key = _toPropertyKey(key); if (key in obj) { Object.defineProperty(obj, key, { value: value, enumerable: true, configurable: true, writable: true }); } else { obj[key] = value; } return obj; }
function _toPropertyKey(t) { var i = _toPrimitive(t, "string"); return "symbol" == _typeof(i) ? i : String(i); }
function _toPrimitive(t, r) { if ("object" != _typeof(t) || !t) return t; var e = t[Symbol.toPrimitive]; if (void 0 !== e) { var i = e.call(t, r || "default"); if ("object" != _typeof(i)) return i; throw new TypeError("@@toPrimitive must return a primitive value."); } return ("string" === r ? String : Number)(t); }
/**
 * @name easy-replace
 * @fileoverview Replace strings with optional lookarounds, but without regexes
 * @version 5.1.1
 * @author Roy Revelt, Codsen Ltd
 * @license MIT
 * {@link https://codsen.com/os/easy-replace/}
 */

var N = "5.1.1";
// var R = exports.version = N;
function L(f, g, n) {
  function O(s) {
    return s != null;
  }
  if (typeof f != "string" || f.length === 0 || typeof g != "string" || g.length === 0) return [];
  var e = [],
    o = Array.from(f),
    t = Array.from(g),
    i;
  for (var s = 0; s < o.length; s++) if (n !== null && n !== void 0 && n.i) {
    if (o[s].toLowerCase() === t[0].toLowerCase()) {
      i = !0;
      for (var l = 0; l < t.length; l++) if (!O(o[s + l]) || !O(t[l]) || o[s + l].toLowerCase() !== t[l].toLowerCase()) {
        i = !1;
        break;
      }
      i && e.push(s);
    }
  } else if (o[s] === t[0]) {
    i = !0;
    for (var _l = 0; _l < t.length; _l++) if (o[s + _l] !== t[_l]) {
      i = !1;
      break;
    }
    i && e.push(s);
  }
  return e;
}
function m(f) {
  function g(n) {
    return n != null;
  }
  return !g(f) || typeof f == "boolean" ? [""] : Array.isArray(f) ? f.filter(function (n) {
    return g(n) && typeof n != "boolean";
  }).map(function (n) {
    return String(n);
  }).filter(function (n) {
    return n.length;
  }) : [String(f)];
}
function v(f, g, n, O) {
  var e = !0,
    o = Array.from(f);
  for (var t = 0, i = o.length; t < i; t++) if (O) {
    if (o[t].toLowerCase() !== g[n - Array.from(f).length + t].toLowerCase()) {
      e = !1;
      break;
    }
  } else if (o[t] !== g[n - Array.from(f).length + t]) {
    e = !1;
    break;
  }
  return e;
}
function w(f, g, n, O) {
  var e = !0,
    o = Array.from(f);
  for (var t = 0, i = o.length; t < i; t++) if (O) {
    if (o[t].toLowerCase() !== g[n + t].toLowerCase()) {
      e = !1;
      break;
    }
  } else if (o[t] !== g[n + t]) {
    e = !1;
    break;
  }
  return e;
}
export default function E(f, g, n) {
  var e = _objectSpread(_objectSpread({}, {
      i: {
        leftOutsideNot: !1,
        leftOutside: !1,
        leftMaybe: !1,
        searchFor: !1,
        rightMaybe: !1,
        rightOutside: !1,
        rightOutsideNot: !1
      }
    }), g),
    o = m(f);
  e.leftOutsideNot = m(e.leftOutsideNot), e.leftOutside = m(e.leftOutside), e.leftMaybe = m(e.leftMaybe), e.searchFor = String(e.searchFor), e.rightMaybe = m(e.rightMaybe), e.rightOutside = m(e.rightOutside), e.rightOutsideNot = m(e.rightOutsideNot);
  var t = m(n),
    i = Array.from(o[0]),
    s,
    l,
    u,
    M,
    a = [],
    A = "",
    k = L(o[0], e.searchFor, {
      i: e.i.searchFor
    });
  for (var b = 0, h = k.length; b < h; b++) {
    var p = k[b];
    if (s = p, l = p + Array.from(e.searchFor).length, e.leftMaybe.length) for (var r = 0, y = e.leftMaybe.length; r < y; r++) {
      u = !0;
      var d = Array.from(e.leftMaybe[r]);
      for (var c = 0, x = d.length; c < x; c++) if (e.i.leftMaybe) {
        if (d[c].toLowerCase() !== i[p - d.length + c].toLowerCase()) {
          u = !1;
          break;
        }
      } else if (d[c] !== i[p - d.length + c]) {
        u = !1;
        break;
      }
      u && p - d.length < s && (s = p - d.length);
    }
    if (e.rightMaybe.length) for (var _r = 0, _y = e.rightMaybe.length; _r < _y; _r++) {
      u = !0;
      var _d = Array.from(e.rightMaybe[_r]);
      for (var _c = 0, _x = _d.length; _c < _x; _c++) if (e.i.rightMaybe) {
        if (_d[_c].toLowerCase() !== i[p + Array.from(e.searchFor).length + _c].toLowerCase()) {
          u = !1;
          break;
        }
      } else if (_d[_c] !== i[p + Array.from(e.searchFor).length + _c]) {
        u = !1;
        break;
      }
      u && l < p + Array.from(e.searchFor).length + _d.length && (l = p + Array.from(e.searchFor).length + _d.length);
    }
    if (e.leftOutside[0] !== "") {
      M = !1;
      for (var _r2 = 0, _y2 = e.leftOutside.length; _r2 < _y2; _r2++) u = v(e.leftOutside[_r2], i, s, e.i.leftOutside), u && (M = !0);
      if (!M) continue;
    }
    if (e.rightOutside[0] !== "") {
      M = !1;
      for (var _r3 = 0, _y3 = e.rightOutside.length; _r3 < _y3; _r3++) u = w(e.rightOutside[_r3], i, l, e.i.rightOutside), u && (M = !0);
      if (!M) continue;
    }
    if (e.leftOutsideNot[0] !== "") {
      for (var _r4 = 0, _y4 = e.leftOutsideNot.length; _r4 < _y4; _r4++) if (u = v(e.leftOutsideNot[_r4], i, s, e.i.leftOutsideNot), u) {
        s = -1, l = -1;
        break;
      }
      if (s === -1) continue;
    }
    if (e.rightOutsideNot[0] !== "") {
      for (var _r5 = 0, _y5 = e.rightOutsideNot.length; _r5 < _y5; _r5++) if (u = w(e.rightOutsideNot[_r5], i, l, e.i.rightOutsideNot), u) {
        s = -1, l = -1;
        break;
      }
      if (s === -1) continue;
    }
    a.push([s, l]);
  }
  if (a.length) a.forEach(function (b, h) {
    a[h + 1] !== void 0 && a[h][1] > a[h + 1][0] && (a[h + 1][0] = a[h][1]);
  }), a.forEach(function (b, h) {
    b[0] === b[1] && a.splice(h, 1);
  });else return o.join("");
  return a.length && a[0][0] !== 0 && (A += i.slice(0, a[0][0]).join("")), a.forEach(function (b, h) {
    A += t.join(""), a[h + 1] !== void 0 ? A += i.slice(a[h][1], a[h + 1][0]).join("") : A += i.slice(a[h][1]).join("");
  }), A;
}
